home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / TextEditorSettings.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-13  |  7.7 KB  |  307 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TextEditorPrefs.cpp
  3.  
  4.     Contains:    TextEditor Preference dialog functions
  5.  
  6.     Written by:    Steve Smith
  7.  
  8.     Copyright:    © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #ifndef _COMPILERDEFS_
  12. #include "CompDefs.h"
  13. #endif
  14.  
  15. // -- OpenDoc Utilities --
  16.  
  17. #ifndef _EXCEPT_
  18. // Exceptions define several important macros (e.g. CHECKENV)
  19. // which are used in the SOM method dispatch glue. If Except.h
  20. // is not included early enough, exceptions may not be thrown
  21. // correctly when returning from a SOM method with "ev" parameter set.
  22. #include <Except.h>
  23. #endif
  24.  
  25. // --- TextEditor Includes ---
  26.  
  27. #ifndef _TEXTEDITORSETTINGS_
  28. #include "TextEditorSettings.h"
  29. #endif
  30.  
  31. #ifndef _TEXTEDITORUTILS_
  32. #include "TextEditorUtils.h"
  33. #endif
  34.  
  35. #ifndef _TEXTEDITORDEF_
  36. #include "TextEditorDef.h"
  37. #endif
  38.  
  39. #ifndef _STDTEXTPROPERTIES_
  40. #include "StdTextProps.h"
  41. #endif
  42.  
  43. #ifndef _TEXTEDITORGLOBALS_
  44. #include "TextEditorGlobals.h"
  45. #endif
  46.  
  47. // --- OpenDoc Includes ---
  48.  
  49. #ifndef _ODTYPES_
  50. #include <ODTypes.h>
  51. #endif
  52.  
  53. #ifndef SOM_ODSession_xh
  54. #include <ODSessn.xh>
  55. #endif
  56.  
  57. #ifndef _EXCEPT_
  58. #include "Except.h"
  59. #endif
  60.  
  61. #ifndef SOM_ODArbitrator_xh
  62. #include <Arbitrat.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODDispatcher_xh
  66. #include <Disptch.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODWindowState_xh
  70. #include <WinStat.xh>
  71. #endif
  72.  
  73. #ifndef SOM_Module_OpenDoc_Foci_defined
  74. #include <Foci.xh>
  75. #endif
  76.  
  77. // --- Unsupported Utilities
  78.  
  79. #ifndef _BARRAY_
  80. #include "BArray.h"
  81. #endif
  82.  
  83. #ifndef _ODMEMORY_
  84. #include "ODMemory.h"
  85. #endif
  86.  
  87. #ifndef _USERSRCM_
  88. #include "UseRsrcM.h"
  89. #endif
  90.  
  91. #ifndef _DLOGUTIL_
  92. #include "DlogUtil.h"
  93. #endif
  94.  
  95. // --- Macintosh Includes ---
  96.  
  97. #ifndef __RESOURCES__
  98. #include <Resources.h>
  99. #endif
  100.  
  101. #ifndef __DIALOGS__
  102. #include <Dialogs.h>
  103. #endif
  104.  
  105. #ifndef __WINDOWS__
  106. #include <Windows.h>
  107. #endif
  108.  
  109. #ifndef __TOOLUTILS__
  110. #include <ToolUtils.h>
  111. #endif
  112.  
  113. #ifndef mathRoutinesIncludes
  114. #include <math routines.h>
  115. #endif
  116.  
  117. #ifndef __FP__
  118. #include <fp.h>
  119. #endif
  120.  
  121. #ifndef __TEXTUTILS__
  122. #include <TextUtils.h>
  123. #endif
  124.  
  125. #ifndef __OSUTILS__
  126. #include <OSUtils.h>
  127. #endif
  128.  
  129. #ifndef __SCRIPT__
  130. #include <Script.h>
  131. #endif
  132.  
  133. #ifndef __FOLDERS__
  134. #include <Folders.h>
  135. #endif
  136.  
  137. #ifndef __FONTS__
  138. #include <Fonts.h>
  139. #endif
  140.  
  141. // --- Textension Includes ---
  142.  
  143. #ifndef _RulerObject_
  144. #include <RulerObject.h>
  145. #endif
  146.  
  147.  
  148. #pragma segment TextEditorSettings
  149.  
  150.  
  151. //------------------------------------------------------------------------------
  152. // ModalSettingsDialog
  153. //------------------------------------------------------------------------------
  154.  
  155. void ModalSettingsDialog( Environment* ev, ODFrame* frame, Rect* margins, 
  156.                           ODUShort* alignment )
  157. {
  158.     const ODUShort kLeftAlignButton = 3;
  159.     const ODUShort kRightAlignButton = 4;
  160.     const ODUShort kCenterAlignButton = 5;
  161.     const ODUShort kJustifiedAlignButton = 6;
  162.     const ODUShort kTopMarginField = 7;
  163.     const ODUShort kLeftMarginField = 8;
  164.     const ODUShort kBottomMarginField = 9;
  165.     const ODUShort kRightMarginField = 10;
  166.     
  167.     TempODPart tPart = frame->AcquirePart(ev);
  168.     ODSession* session = ODGetSession(ev, tPart);
  169.     
  170.     // Our About box is modal so we must request the Modal focus to prevent
  171.     // multiple modal dialogs being displayed simultaneously.
  172.     
  173.     if ( session->GetArbitrator(ev)->RequestFocus(ev, gGlobals->fModalFocus,frame) )
  174.     {
  175.         ODSShort    itemHit;
  176.         short        iType;
  177.         Handle        iHandle;
  178.         Rect        iRect;
  179.         Str255        strValue;
  180.         short        currentAlignment;
  181.         
  182.         CUsingLibraryResources res;
  183.         
  184.         session->GetWindowState(ev)->DeactivateFrontWindows(ev);
  185.             // Dim the frontmost document window.
  186.         
  187.         ODBoolean hasMarginItems = frame->IsRoot(ev);
  188.         ODSShort dlogID = hasMarginItems ? kSettingsDialogID : kSettingsNoMarginsDialogID;
  189.         DialogPtr dialog = GetNewDialog(dlogID, kODNULL, (WindowPtr)-1L);
  190.         
  191.         // Set dialog font and other std things.
  192.         SetDialogDefaults(dialog, kDialogFontInfoID, kSettingsFontIndex);
  193.         
  194.         // Stuff current margins into dialog fields
  195.         if (hasMarginItems)
  196.         {
  197.             GetDialogItem(dialog, kTopMarginField, &iType, &iHandle, &iRect);
  198.             ConvertPixelsToNumStr(margins->top, &strValue);
  199.             SetDialogItemText(iHandle, strValue);
  200.             
  201.             GetDialogItem(dialog, kLeftMarginField, &iType, &iHandle, &iRect);
  202.             ConvertPixelsToNumStr(margins->left, &strValue);
  203.             SetDialogItemText(iHandle, strValue);
  204.     
  205.             GetDialogItem(dialog, kBottomMarginField, &iType, &iHandle, &iRect);
  206.             ConvertPixelsToNumStr(margins->bottom, &strValue);
  207.             SetDialogItemText(iHandle, strValue);
  208.     
  209.             GetDialogItem(dialog, kRightMarginField, &iType, &iHandle, &iRect);
  210.             ConvertPixelsToNumStr(margins->right, &strValue);
  211.             SetDialogItemText(iHandle, strValue);
  212.         }
  213.  
  214.         // Set the appropriate radio button for the current justification
  215.         switch ( *alignment ) 
  216.         {
  217.             case left:                currentAlignment = kLeftAlignButton;        break;
  218.             case center:            currentAlignment = kCenterAlignButton;        break;
  219.             case right:                currentAlignment = kRightAlignButton;        break;
  220.             case fulljustification: currentAlignment = kJustifiedAlignButton;    break;
  221.         }
  222.         
  223.         GetDialogItem(dialog, currentAlignment, &iType, &iHandle, &iRect);
  224.         SetControlValue((ControlHandle) iHandle, 1);
  225.         
  226.         ShowWindow(dialog);
  227.         
  228.         ModalFilterUPP otherDialogProc = NewModalFilterProc(OtherDialogFilter);
  229.         
  230.         // Select the text in the top margin field
  231.         SelectDialogItemText(dialog, kTopMarginField, 0, 32767);
  232.         
  233.         do
  234.         {
  235.             ModalDialog(kODNULL, &itemHit);
  236.             
  237.             switch (itemHit) 
  238.             {
  239.                 case kLeftAlignButton:
  240.                 case kCenterAlignButton:
  241.                 case kRightAlignButton:
  242.                 case kJustifiedAlignButton:
  243.                     GetDialogItem(dialog, kLeftAlignButton, &iType, &iHandle, &iRect);
  244.                     SetControlValue((ControlHandle) iHandle, (itemHit == kLeftAlignButton));
  245.                     
  246.                     GetDialogItem(dialog, kCenterAlignButton, &iType, &iHandle, &iRect);
  247.                     SetControlValue((ControlHandle) iHandle, (itemHit == kCenterAlignButton));
  248.                     
  249.                     GetDialogItem(dialog, kRightAlignButton, &iType, &iHandle, &iRect);
  250.                     SetControlValue((ControlHandle) iHandle, (itemHit == kRightAlignButton));
  251.                     
  252.                     GetDialogItem(dialog, kJustifiedAlignButton, &iType, &iHandle, &iRect);
  253.                     SetControlValue((ControlHandle) iHandle, (itemHit == kJustifiedAlignButton));
  254.                     break;
  255.             }
  256.         }
  257.         while ( itemHit != ok && itemHit != cancel );
  258.         
  259.         DisposeRoutineDescriptor(otherDialogProc);
  260.  
  261.         if ( itemHit == ok )
  262.         {
  263.             // retrieve the "new" margins settings
  264.             
  265.             if ( hasMarginItems )
  266.             {
  267.                 GetDialogItem(dialog, kTopMarginField, &iType, &iHandle, &iRect);
  268.                 GetDialogItemText(iHandle, strValue);
  269.                 margins->top = ConvertNumStrToPixels(strValue);
  270.     
  271.                 GetDialogItem(dialog, kLeftMarginField, &iType, &iHandle, &iRect);
  272.                 GetDialogItemText(iHandle, strValue);
  273.                 margins->left = ConvertNumStrToPixels(strValue);
  274.     
  275.                 GetDialogItem(dialog, kBottomMarginField, &iType, &iHandle, &iRect);
  276.                 GetDialogItemText(iHandle, strValue);
  277.                 margins->bottom = ConvertNumStrToPixels(strValue);
  278.     
  279.                 GetDialogItem(dialog, kRightMarginField, &iType, &iHandle, &iRect);
  280.                 GetDialogItemText(iHandle, strValue);
  281.                 margins->right = ConvertNumStrToPixels(strValue);
  282.             }
  283.             
  284.             // retrieve the "new" alignment setting
  285.             
  286.             GetDialogItem(dialog, kLeftAlignButton, &iType, &iHandle, &iRect);
  287.             *alignment = GetControlValue((ControlHandle) iHandle) ? left : *alignment;
  288.             GetDialogItem(dialog, kCenterAlignButton, &iType, &iHandle, &iRect);
  289.             *alignment = GetControlValue((ControlHandle) iHandle) ? center : *alignment;
  290.             GetDialogItem(dialog, kRightAlignButton, &iType, &iHandle, &iRect);
  291.             *alignment = GetControlValue((ControlHandle) iHandle) ? right : *alignment;
  292.             GetDialogItem(dialog, kJustifiedAlignButton, &iType, &iHandle, &iRect);
  293.             *alignment = GetControlValue((ControlHandle) iHandle) ? fulljustification : *alignment;
  294.         }
  295.  
  296.         DisposeDialog(dialog);
  297.  
  298.         session->GetArbitrator(ev)->RelinquishFocus(ev, gGlobals->fModalFocus, frame);
  299.             // Inform the Arbitrator that we no longer require the Modal focus.
  300.         
  301.         session->GetWindowState(ev)->ActivateFrontWindows(ev);
  302.             // Hilite the frontmost document window.
  303.     }
  304. }
  305.  
  306.  
  307.